using EnvDTE;
using NUnitGenAddIn.Core.Test;

namespace NUnitGenAddIn.VS2008.Test
{
    /// <summary>
    /// Mock File Code Model 2008
    /// </summary>
    public class MockFileCodeModel2008 : MockFileCodeModel
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="MockFileCodeModel2008"/> class.
        /// </summary>
        /// <param name="codeElements">The code elements.</param>
        public MockFileCodeModel2008(MockCodeElements codeElements) : base(codeElements)
        {}

        /// <summary>
        /// Codes the element from point.
        /// </summary>
        /// <param name="point">The point.</param>
        /// <param name="scope">The scope.</param>
        /// <returns></returns>
        public override CodeElement CodeElementFromPoint(TextPoint point, vsCMElement scope)
        {
            return codeElementFromPoint(scope, CodeElements);
        }

        /// <summary>
        /// Codes the element from point.
        /// </summary>
        /// <param name="scope">The scope.</param>
        /// <param name="codeElements">The code elements.</param>
        /// <returns><see cref="CodeElement"/> object</returns>
        private static CodeElement codeElementFromPoint(vsCMElement scope, CodeElements codeElements)
        {
            foreach (CodeElement e in codeElements)
            {
                if (e.Kind == scope)
                {
                    return e;
                }
                
                if (e.Children.Count > 0)
                {
                    return codeElementFromPoint(scope, e.Children);
                }
            }

            return null;
        }
    }
}